from matplotlib import pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

A = 1050000
rate = 0.0465
D = 3000

first_month = []
last_month = []
totals = []
for N in range(10, 31):
    total = 0
    for n in range(1, N + 1):
        x = (rate**2*A-D*((1+rate)**N-rate*N-1)) / \
            (rate**2*N+rate*((1+rate)**N-rate*N-1))+A*rate+D*(n-1)
        if n == 1:
            first_month.append(x)
        elif n == N:
            last_month.append(x)
        total += x
    totals.append(total)

# print(list(i / 12 for i in first_month))
print(list(i / 12 for i in last_month))
# print(totals)

# plt.title('等额年递增：最高月供-年限图')
# plt.axis([10, 30, 7000, 13000])
# plt.xticks(list(range(10, 31, 1)))
# plt.yticks(list(range(7000, 13001, 1000)))
# plt.xlabel('年限（年）')
# plt.ylabel('最高月供（元）')
# plt.plot(list(range(10, 31, 1)), list(
#     i / 12 for i in last_month), linestyle='-')
# plt.fill_between([10, 30], [8000] * 2, [7000] * 2, facecolor='lightgray')
# plt.grid()
# plt.show()
